package com.art.museumbackend.service.impl;

import com.art.museumbackend.entity.Columns;
import com.art.museumbackend.mapper.ColumnMapper;
import com.art.museumbackend.service.ColumnService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yezi
 * @since 2024-12-07
 */
@Service
public class ColumnServiceImpl extends ServiceImpl<ColumnMapper, Columns> implements ColumnService {
    @Autowired
    private ColumnMapper columnMapper;

    @Override
    public void addColumn(Columns columns) {
        //补充属性值
        columns.setCreatedTime(LocalDateTime.now());
        columns.setUpdatedTime(LocalDateTime.now());
         columnMapper.addColumn(columns);
    }

    @Override
    public List<Columns> listAllColumns() {
        return columnMapper.selectAll();
    }

    @Override
    public Columns getColumnById(Integer cid) {
        return columnMapper.selectByCid(cid);
    }

    @Override
    public void updateColumn(Columns columns) {
        columns.setUpdatedTime(LocalDateTime.now());
        columnMapper.updateColumn(columns);
    }

    @Override
    public void deleteColumn(Integer columnId) {
        columnMapper.deleteColumn(columnId);
    }

    @Override
    public List<Columns> getParentColumns() {
        return columnMapper.selectParentColumns();
    }

    @Override
    public List<Columns> getChildrenColumns(Integer pid) {
        return columnMapper.selectChildrenColumns(pid);
    }

    @Override
    public List<Columns> selectAllChildrenColumns() {
        return columnMapper.selectAllChildrenColumns();
    }

}
